package com.actitime.projectAndCustomerTest;

import java.io.IOException;




import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.actitime.businesslib.ProjectAndCustomerLib;
import com.acttime.GenericLib.Driver;
import com.acttime.GenericLib.GetExcelLib;
import com.acttime.GenericLib.WebDriverCommonUtil;


public class ProjectAndCustomerTest {

	
	GetExcelLib elib = new GetExcelLib();
	WebDriverCommonUtil com = new WebDriverCommonUtil();
	ProjectAndCustomerLib pLib = new ProjectAndCustomerLib();
	String customerName = "Upendra";
	@Test
	public void verifyCustomer()
	{
		// Create New Customer
		pLib.navigateToProjectAndCustomer();
		com.waitForPageToLoad();
		pLib.createNewCustomer(customerName);
		System.out.println("Customer Created :" + customerName);
		Assert.assertEquals(pLib.verifyCustomer(customerName),true);
		System.out.println("Verified Customer :" + customerName);
		pLib.deleteCustomer(customerName);
		System.out.println("Customer Deleted...." + customerName);
	}
	
	@Test(priority=1)
	public void modifyCustomer()
	{
//		pLib.navigateToProjectAndCustomer();
//		com.waitForPageToLoad();
//		pLib.createNewCustomer(customerName);
		System.out.println("Customer Created");
//		Assert.assertEquals(pLib.verifyCustomer(customerName),true);
		System.out.println("Verified Customer");
//		pLib.modifyCustomer();
		System.out.println("Modified Customer");
//		pLib.deleteCustomer(customerName);
		System.out.println("Customer Deleted....");
	}
	@BeforeMethod
	public void loginToActiTime() throws InvalidFormatException, IOException
	{
		//Get User Name and Password
		String userName = elib.getExcelData("actitime", 1, 1);
		String passWord = elib.getExcelData("actitime", 1, 2);
		// Login to acti-time
		com.enterValuesInField("username", userName);
		com.enterValuesInField("pwd", passWord);
		com.clickById("loginButton");
		com.waitForPageToLoad();
		System.out.println("Logged in....");
	}
		
	@AfterMethod
	public void logoutActiTime()
	{
		//Logout from app
		com.clickById("logoutLink");
		System.out.println("Logged out.....");
	}
	
	@BeforeClass
	public void launchActtime()
	{
		// Navigate to web page
		Driver.driver.get("http://krishna/login.do");	
	}
		
	@AfterClass
	public void closeActiTime()
	{
		// close browser and quit app
		Driver.driver.quit();
	}
}
